package com.example.wanted.service;

import com.example.wanted.model.Like_star;
import com.example.wanted.repository.Like_starRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class Like_starService {
    final Like_starRepository like_starRepository;

    @Autowired
    public Like_starService(@Qualifier("like_star") Like_starRepository like_starRepository) {
        this.like_starRepository = like_starRepository;
    }

    public void save(Like_star like_star){
        like_starRepository.save(like_star);
    }

    public boolean findLikeByUserAndQuestion(String user_id,Long question_id) {
        if(like_starRepository.findLikeByUserAndQuestion(user_id,question_id)){
            return true;
        }
        else return false;
    }
    public boolean findStarByUserAndQuestion(String user_id,Long question_id) {
        if(like_starRepository.findStarByUserAndQuestion(user_id,question_id)){
            return true;
        }
        else return false;
    }

    public boolean canfindByUserAndQuestion(String user_id,Long question_id){
        if((like_starRepository.findByUserAndQuestion(user_id,question_id))!=null){
            System.out.println(like_starRepository.findByUserAndQuestion(user_id,question_id));
            return true;
        }
        else{
            return false;
        }
    }

    public Like_star findByUserAndQuestion(String user_id,Long question_id) {
        return like_starRepository.findByUserAndQuestion(user_id, question_id);
    }


    public void updateByUserAndQuestion(Like_star like_star){
        Like_star old=like_starRepository.findByUserAndQuestion(like_star.getUser_id(),like_star.getQuestion_id());
        System.out.println(old);
        old.setLike_count(like_star.getLike_count());
        old.setStar(like_star.getStar());
        like_starRepository.save(old);
    }

}
